/**     
* @Title: DataSourceConfig.java   
* @Package me.security.example.config   
* @Description: TODO   
* @author xaoyaoyao
* @date 2017年8月23日 下午4:32:06
*/
package me.security.example.config;

import java.beans.PropertyVetoException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * @ClassName: DataSourceConfig
 * @Description: TODO
 * @author xaoyaoyao
 * @date 2017年8月23日 下午4:32:06
 * 
 */
@Configuration
public class DataSourceConfig {

	@Autowired
	private Environment env;

	@Bean(name = "dataSource")
	public ComboPooledDataSource dataSource() throws PropertyVetoException {
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		dataSource.setDriverClass(env.getProperty("ms.db.driverClassName"));
		dataSource.setJdbcUrl(env.getProperty("ms.db.url"));
		dataSource.setUser(env.getProperty("ms.db.username"));
		dataSource.setPassword(env.getProperty("ms.db.password"));
		dataSource.setMaxPoolSize(20);
		dataSource.setMinPoolSize(5);
		dataSource.setInitialPoolSize(10);
		dataSource.setMaxIdleTime(300);
		dataSource.setAcquireIncrement(5);
		dataSource.setIdleConnectionTestPeriod(60);
		return dataSource;
	}
}